/* EasyWay Game Engine
 * Copyright (C) 2006 Daniele Paggi.
 *  
 * Written by: 2006 Daniele Paggi<dshnt@hotmail.com>
 *   
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.easyway.objects.sprites2D;

import java.io.Serializable;
import java.util.ArrayList;

import org.easyway.annotations.editor.Creator;
import org.easyway.annotations.editor.Info;
import org.easyway.annotations.editor.UEditor;
import org.easyway.annotations.editor.X;
import org.easyway.annotations.editor.Y;
import org.easyway.interfaces.base.ITexture;
import org.easyway.interfaces.sprites.ISpriteColl;

/**
 * A simple that can be used to tests the collisions.
 * 
 * @Author Daniele Paggi
 */
@UEditor//
public class SpriteColl extends Sprite implements ISpriteColl, Serializable {

	/**
	 * generated version
	 */
	private static final long serialVersionUID = 3582682613742361484L;

	public ArrayList<ISpriteColl> collisionList = new ArrayList<ISpriteColl>(6);

	/**
	 * indicates if the object is added or not to the auto-collisionLists.
	 */
	protected boolean collAdded = false;

	/** the collision mask */
	private Mask mask;

	/**
	 * returns the collision mask
	 * 
	 * @param mask
	 *            the collision mask
	 */
	public void setMask(Mask mask) {
		this.mask = mask;
	}

	// -----------------------------------------------------------------
	// ---------------------CONSTRUCTORS--------------------------------
	// -----------------------------------------------------------------

	public SpriteColl() {
		this(0, 0, 0, null, 0);
	}

	public SpriteColl(int layer) {
		this(0, 0, 0, null, layer);
	}

	public SpriteColl(float x, float y) {
		this(x, y, 0, null, 0);
	}

	public SpriteColl(float x, float y, float z) {
		this(x, y, z, null, 0);
	}

	@Creator("x, y, imgage")//
	public SpriteColl(@X @Info("x") float x,@Y @Info("y") float y, ITexture img) {
		this(x, y, 0, img, 0);
	}

	public SpriteColl(float x, float y, int layer) {
		this(x, y, 0, null, layer);
	}

	@Creator("x, y, imgage, layer")//
	public SpriteColl(@X @Info("x") float x,@Y @Info("y") float y, ITexture img,
			@Info("layer") int layer) {
		this(x, y, 0, img, layer);
	}

	public SpriteColl(ITexture img) {
		this(0, 0, 0, img, 0);
	}

	public SpriteColl(ITexture img, int layer) {
		this(0, 0, 0, img, layer);
	}

	public SpriteColl(float x, float y, float z, ITexture img, int layer) {
		super(x, y, z, img, layer);
	}
	
	public SpriteColl(SpriteColl obj) {
		super(obj);
		mask = obj.mask;
	}

	// -----------------------------------------------------------------

	public SpriteColl(boolean quad) {
		this(0, 0, 0, null, 0, quad);
	}

	public SpriteColl(int layer, boolean quad) {
		this(0, 0, 0, null, layer, quad);
	}

	public SpriteColl(float x, float y, boolean quad) {
		this(x, y, 0, null, 0, quad);
	}

	public SpriteColl(float x, float y, float z, boolean quad) {
		this(x, y, z, null, 0, quad);
	}

	@Creator("x, y, image, quad")//
	public SpriteColl(@X @Info("x") float x,@Y @Info("y") float y, ITexture img,
			@Info("use quad") boolean quad) {
		this(x, y, 0, img, 0, quad);
	}

	public SpriteColl(float x, float y, int layer, boolean quad) {
		this(x, y, 0, null, layer, quad);
	}

	public SpriteColl(float x, float y, ITexture img, int layer, boolean quad) {
		this(x, y, 0, img, layer, quad);
	}

	public SpriteColl(ITexture img, boolean quad) {
		this(0, 0, 0, img, 0, quad);
	}

	public SpriteColl(ITexture img, int layer, boolean quad) {
		this(0, 0, 0, img, layer, quad);
	}

	public SpriteColl(float x, float y, float z, ITexture img, int layer,
			boolean quad) {
		super(x, y, z, img, layer, quad);
	}

	// -----------------------------------------------------------------
	// --------------------- OTHER -------------------------------------
	// -----------------------------------------------------------------

	public float getRotation2D() {
		return anglez;
	}

	public Mask getMask() {
		if (mask != null)
			return mask;
		if (image != null)
			return image.getMask();
		org.easyway.utils.Utility.error("the sprite hasn't any mask",
			"Sprite.getMask()");
		return null;
	}

	public ArrayList<ISpriteColl> getCollisionList() {
		return collisionList;
	}

	public void onCollision() {
	}

	public boolean getAddedToCollisionList() {
		return collAdded;
	}

	public void setAddedToCollisionList(boolean value) {
		collAdded = value;
	}
	
	public Object clone() {
		return new SpriteColl(this);
	}
}
